package com.tencent.iov.cowin.befsale.clue.config;

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Caychen
 * @Date: 2021/10/20 15:25
 * @Description:
 */
@Configuration
@Slf4j
public class RedissonConfig {

    @Bean
    public RedissonClient redissonClient(RedisProperties redisProperties) {
        Config config = new Config();
        config.useSingleServer()
                .setDatabase(redisProperties.getDatabase())
                .setPassword(redisProperties.getPassword())
                .setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
        RedissonClient redissonClient = Redisson.create(config);

        log.info("初始化Redisson组件");
        return redissonClient;
    }
}
